package com.sk.bilibili.view.fragment.main.home.shop;

import android.content.Context;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.shop.BaseCoverAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.shop.BaseGoodsAdapter;
import com.sk.bilibili.bean.Cover;
import com.sk.bilibili.bean.Goods;
import com.sk.bilibili.model.fragment.main.shop.CoverModel;
import com.sk.bilibili.model.fragment.main.shop.GoodsModel;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.lang.reflect.Constructor;
import java.util.List;

import lombok.SneakyThrows;

public class CoverFragment extends BaseRefreshFragment<CoverModel> {

    private BaseCoverAdapter<?> baseCoverAdapter;
    private Constructor<? extends BaseCoverAdapter<?>> constructor;

    @SneakyThrows
    public CoverFragment(Class<? extends BaseCoverAdapter<?>> clazz) {
        constructor = clazz.getConstructor(Context.class);
    }

    @SneakyThrows
    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        baseCoverAdapter = constructor.newInstance(getContext());
        adapter.addAdapter(baseCoverAdapter);
    }

    @Override
    public void onBottom() {
        model.loadData();
    }

    @Override
    public void onRefresh() {
        model.refreshData();
    }

    public void loadDataSuccess(List<Cover> records) {
        if(records.isEmpty()){
            toast("没有更多数据了");
        }else {
            baseCoverAdapter.addData(records);
        }
    }

    public void refreshDataSuccess(List<Cover> records) {
        baseCoverAdapter.setData(records);
        cancelRefresh();
    }

}